#!/bin/sh

BASE_DIR=$(cd "$(dirname "$0")"; pwd)/
cd $BASE_DIR

# 自动从bootstrap.properties中读取配置,不需要调整shell文件了
app_conf_dir=conf/

app_name=`cat $app_conf_dir/bootstrap.properties |grep "^app.id" | tail -n 1 | cut -d "=" -f2- | awk '{print $1}'`
app_meta=`cat $app_conf_dir/bootstrap.properties |grep "^apollo.meta" | tail -n 1 | cut -d "=" -f2- | awk '{print $1}'`

app_jar=$(ls *.jar|tail -n 1)

app_log_path=/log/$app_name

PID=`/bin/ps -ef | grep -v .sh | grep java | grep $app_jar | grep -v grep |awk '{print $2}'`

if [ -n "$PID" ]; then
    echo "进程已经存在，进程号: $PID"
    exit
fi

CMD="\
/usr/jdk/bin/java -server -Xms512m -Xmx768m -jar $app_jar \
 --spring.profiles.active=dev \
 --spring.config.location=$app_conf_dir \
 --apollo.meta=${app_meta} \
 --logging.path=$app_log_path \
 --logging.config=${app_conf_dir}logback-spring.xml \
"

echo $CMD

`$CMD > /dev/null &`

PID=`/bin/ps -ef | grep -v .sh | grep java | grep $app_jar | grep -v grep |awk '{print $2}'`

if [ -n "$PID" ]; then
	echo "$app_jar启动成功，进程号: $PID"
    exit
fi

echo "$app_jar启动失败，请检查日志 $app_log_path "
exit
